/*
 *   AS IS License 
 *  ==Naive Coders==
 */
package com.naivecoders.refex.functions;

import com.naivecoders.refex.CallTrail.CallTrailState;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author andrew
 */
public class InvocationException extends Exception {

    private final List<ListFunction> stack = new ArrayList<>();
    private CallTrailState trail;

    public InvocationException(Throwable cause, String message, Object... args) {
        super(String.format(message, args), cause);
    }

    public InvocationException(String message, Object... args) {
        super(String.format(message, args));
    }

    public void appendStackEntry(ListFunction entry) {
        stack.add(entry);
    }

    public void dump(PrintStream output) {
        output.println(getMessage());
        if (trail != null) {
            trail.dump(output);
        }

        for (ListFunction lf : stack) {
            output.println(lf);
        }
    }

    public void setTrail(CallTrailState t) {
        this.trail = t;
    }
}
